import traceback

try:
    1 / 0
except:
    with open("/tmp/foo.log", "a") as f:
        traceback.print_exc(file=f)
